<template>
  <div class="Commissionrecord">
    <div class="myMoney qqq">
      <div class="recharge one">
        <div class="money">
          总收益
          <!-- <span class="biao1">年</span> -->
        </div>
        <div class="xian"></div>
        <div class="operation one">
          <!-- <img src="../../assets/zongshouyi.png" class='ibiao'> -->
          <b>{{ all_income || 0 }}元</b>
        </div>
      </div>
      <div class="recharge tow">
        <div class="money">
          总返佣
          <!-- <span class="biao2">月</span> -->
        </div>
        <div class="xian"></div>
        <div class="operation">
          <div>
            <!-- <img src="../../assets/aaaaa.png" class='ibiao'> -->
            <b>{{ all_brokerage || 0 }}元</b>
          </div>
        </div>
      </div>
      <div class="recharge three">
        <div class="money">
          总差额
          <!-- <span class="biao3">周</span> -->
        </div>
        <div class="xian"></div>
        <div class="operation">
          <!-- <img src="../../assets/aaaaa.png" class='ibiao'> -->
          <b>{{ all_payoff || 0 }}元</b>
        </div>
      </div>
    </div>
    <div class="block">
      <el-col :span="24" class="operation">
        <div class="block">
          <el-date-picker class="timetable" v-model="riqixuanze" type="daterange" range-separator="至" start-placeholder="开始日期"
            end-placeholder="结束日期" @change="timeChange"></el-date-picker>
          <el-button type="primary" class="sousuo" @click="xuanzeriqi">搜索</el-button>
        </div>
      </el-col>
    </div>
    <div class="pczhanshi hidden-xs-only">
      <!-- PC端 -->
      <el-table :data="listData" style="width: 100%">
        <el-table-column prop="create_time" label="创建时间"></el-table-column>
        <el-table-column prop="all_day_pay" label="总充值">
          <template slot-scope="scope">
            <span>{{scope.row.all_day_pay}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="all_day_brokerage" label="返佣金额">
          <template slot-scope="scope">
            <span>{{scope.row.all_day_brokerage}}</span>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="查看" width="100">
          <template slot-scope="scope">
            <el-button @click="handleClick(scope.row.create_time)" type="text" size="small">详情</el-button>
          </template>
        </el-table-column>
        <template slot="empty" v-if="loding">
          <img class="data-pic" src="@/assets/BGT.png" alt="" />
        </template>
      </el-table>
    </div>
    <!-- 分页 -->
    <div class="dashadiao hidden-xs-only" style="height: 70px;">
      <el-pagination
       @size-change="handleSizeChange"
       @current-change="handleCurrentChange"
       :current-page="currentPage2"
       :page-sizes="xiabiao"
       :page-size="xianshitiaoshu"
       layout="total, sizes, prev, pager, next, jumper"
       :total="tiaoshu">
      </el-pagination>
    </div>

    <div class="zhanshi hidden-sm-and-up">
      <el-collapse v-model="activeName" accordion>
        <!-- 移动端 -->
        <el-collapse-item :name="index" v-for="(x, index) in listData" :key="index">
          <template slot="title">
            <span>业务时间: &nbsp;{{ x.create_time}}</span>
          </template>
          <div class="sj">总充值: &nbsp;{{ x.all_day_pay }}</div>
          <div class="sj">返佣金额: &nbsp;{{ x.all_day_brokerage }}</div>
          <a class="sjtiao" href="javascript:void(0);" @click="handleClick(x.create_time)">查看详情</a>
        </el-collapse-item>
      </el-collapse>
    </div>
    <div class="dashadiao hidden-sm-and-up" style="height: 70px;">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage2"
        :page-sizes="xiabiao" :page-size="xianshitiaoshu" layout="total, sizes, prev, pager, next" :total="tiaoshu">
      </el-pagination>
    </div>
  </div>
</template>
<script>
  import moment from "moment";
  export default {
    props: {},
    data() {
      return {
        begin_time:'',
        end_time:'',
        listData:[],
        page_index:1,
        page_cnt:10,
        all_brokerage:'',
        all_income:'',
        all_payoff:'',
        xiabiao: [10, 20, 50, 100],
        pickerOptions: {
          shortcuts: [{
              text: "最近一周",
              onClick(picker) {
                const end = new Date();
                const start = new Date();
                start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
                picker.$emit("pick", [start, end]);
              }
            },
            {
              text: "最近一个月",
              onClick(picker) {
                const end = new Date();
                const start = new Date();
                start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
                picker.$emit("pick", [start, end]);
              }
            },
            {
              text: "最近三个月",
              onClick(picker) {
                const end = new Date();
                const start = new Date();
                start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
                picker.$emit("pick", [start, end]);
              }
            }
          ]
        },
        riqixuanze: [],
        tableData: [],
        shouji: [],
        pc: "1",
        currentPage2: 1,
        shijian1: "",
        shijian2: "",
        kaishitiaoshu: 0,
        dangyetiaoshu: 1,
        xianshitiaoshu: 10, //页面显示的页数
        jieshutiaoshu: 10,
        activeName: "",
        zongshouyi: "",
        zongfanyong: "",
        zongchae: "",
        zongtiaoshu: "", //总条数  接口返回的总条数
        tiaoshu: 0, //有多少页
        fanyong1: "",
        fanyong2: "",
        chae1: "",
        chae2: "",
        canshu: "",
        loding: false
      };
    },
    computed: {},
    created() {
      let date = [];
      let start =
        moment()
        .add("month", 0)
        .format("YYYY-MM") + "-01";
      let start_1 = moment(start).format("YYYY-MM-DD");
      let end = moment(start)
        .add("month", 1)
        .add("days", -1)
        .format("YYYY-MM-DD");
      date.push(start_1);
      date.push(end);
      this.shijian1 = date[0];
      this.shijian2 = date[1];
      this.commisslist();
      // this.zhanshi();
    },
    mounted() {},
    watch: {
      riqixuanze(newVal, oldVal) {
        if (newVal == null) {
          this.riqixuanze = [];
        }
        if (newVal) {
          this.kaishishu = 0;
          this.jieshushu = this.limt;
        }
      }
    },
    methods: {
      timeChange(time) {
        if (time) {
          const start = this.$moment(time[0])
            .startOf("day")
            .format("YYYY-MM-DD");
          const end = this.$moment(time[1])
            .endOf("day")
            .format("YYYY-MM-DD");
          this.riqixuanze = [start, end];
        } else {
          this.riqixuanze = [];
        }
      },
      //返佣记录接口
      async commisslist() {
        let data={
          begin_time:this.begin_time,
          end_time:this.end_time,
          page_index:this.page_index,
          page_cnt:this.page_cnt
        }
        const [err, res] = await this.$http.request({
          url: "/everyDayIncome",
          method: "GET",
          data
        });
        if (err) return;
        console.log(res.data.data);
        this.all_brokerage=res.data.data.all_brokerage
        this.all_income=res.data.data.all_income
        this.all_payoff=res.data.data.all_payoff
        this.listData=res.data.data.brokerage_day_list
        this.tiaoshu=res.data.data.list_cnt
      },
        //一页多少条
      async handleSizeChange(val) {
        this.page_cnt=val
        this.commisslist()
      },
      //分页点击第几页
      async handleCurrentChange(val) {
        this.page_index=val
        this.commisslist()
      },
      //搜索触发
      async xuanzeriqi(){
         this.begin_time=this.riqixuanze[0]
         this.end_time=this.riqixuanze[1]
         this.commisslist();
      },

      //详情触发
      handleClick(row) {
        // console.log(row)
        // this.$router.push("/xiangqing?shijian=" + row);
        this.$router.push({path:'/xiangqing',query:{create_time:row}})
      },
      // sjxq() {
      //   this.$router.push(
      //     "/xiangqing?shijian=" + this.shouji[this.activeName].ctime
      //   );
      // }
    },
    components: {}
  };
</script>

<style scoped lang="stylus">
  @import './Commissionrecord.styl';
</style>
